#install.packages("tidycensus")
# Load necessary libraries
library(tidycensus)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
#install.packages("factoextra")
library(factoextra)
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
#install.packages("ggplot2")
#install.packages("usmap")
#install.packages("maps")
library(ggplot2)
library(usmap)
library(maps)
#Abhay
#Employment - K202301 for 2021
# Get ACS data
df1 <- get_acs(geography = "state",
table = "K202301",
year = 2021,
survey = "acs1-year",
cache_table = TRUE)
## Getting data from the ACS 1-year Supplemental Estimates. Data are available for geographies with populations of 20,000 and greater.
## Loading ACSSE variables for 2021 from table K202301 and caching the dataset for faster future access.
variables_df1 <- data.frame(
variable = c("K202301_001", "K202301_002", "K202301_003", "K202301_004", "K202301_005", "K202301_006", "K202301_007"),
label = c("Total", "In labor force:", "Civilian labor force:", "Employed",
"Unemployed", "In Armed Forces",
"Not in labor force")
)
# Joining the data with the variable labels to get the descriptive names
df1_labeled <- df1 %>%
left_join(variables_df1, by = "variable")
# Reshapeing the data so that state names are rows and variable labels are columns
df1_wide <- df1_labeled %>%
pivot_wider(names_from = label, values_from = estimate, id_cols = NAME)
# Calculate employment rates
df1_wide <- df1_wide %>%
mutate(
EmploymentRate = `Employed` / `Total` * 100,
UnemploymentRate = `Unemployed` / `Total` * 100,
NotInLaborForceRate = `Not in labor force` / `Total` * 100
)
# Plotting employment rates
library(ggplot2)
ggplot(df1_wide, aes(x = reorder(NAME, -EmploymentRate), y = EmploymentRate)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(x = "State", y = "Employment Rate (%)", title = "Employment Rates by State") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
# Plotting labor force participation
ggplot(df1_wide, aes(x = NAME)) +
geom_bar(aes(y = `Employed`, fill = "Employed"), stat = "identity") +
geom_bar(aes(y = `Unemployed`, fill = "Unemployed"), stat = "identity") +
geom_bar(aes(y = `In Armed Forces`, fill = "Armed Forces"), stat = "identity") +
scale_fill_manual(values = c("Employed" = "green", "Unemployed" = "red", "Armed Forces" = "blue")) +
theme(axis.text.x = element_text(angle = 90)) +
labs(x = "State", y = "Number of People", fill = "Category", title = "Labor Force Participation by State")
ggplot(df1_wide, aes(x = UnemploymentRate)) +
geom_histogram(binwidth = 1, fill = "tomato", color = "black") +
labs(x = "Unemployment Rate (%)", y = "Number of States", title = "Distribution of Unemployment Rates across States")
# Correlation analysis
employment_data <- df1_wide %>%
select(`Employed`, `Unemployed`, `In Armed Forces`, `Not in labor force`)
correlation_matrix <- cor(employment_data, use = "complete.obs")
# Visualize the correlation matrix
library(corrplot)
## corrplot 0.92 loaded
corrplot(correlation_matrix, method = "circle")
# Convert state names to abbreviations
state_abbreviations <- state.abb[match(df1_wide$NAME, state.name)]
df1_wide$state <- state_abbreviations
df1_wide$EmploymentRate <- df1_wide$`Employed` / df1_wide$Total * 100
# Plot the map with employment rate
plot_usmap(data = df1_wide, values = "EmploymentRate", labels = TRUE) +
scale_fill_continuous(name = "Employment Rate (%)", label = scales::percent_format()) +
theme(legend.position = "right") +
labs(title = "Employment Rate by State in 2021")
#Neha
#Education - K201501
df2 <- get_acs(geography = "state",
table = "K201501",
year = 2021,
survey = "acs1/subject",cache_table = TRUE)
## Getting data from the ACS 1-year Supplemental Estimates. Data are available for geographies with populations of 20,000 and greater.
## Loading ACSSE variables for 2021 from table K201501 and caching the dataset for faster future access.
variables_df2 <- data.frame(
variable = c("K201501_001", "K201501_002", "K201501_003", "K201501_004", "K201501_005", "K201501_006", "K201501_007", "K201501_008"),
label = c("Education_Total_students", "Education_Below_9th grade", "Education_9th to 12th grade_no diploma", "Education_High_school_graduate", "Education_Some college_no degree", "Education_Associates_degree", "Education_Bachelors_degree", "Education_Graduate_professional degree")
)
df2_labeled <- df2 %>%
left_join(variables_df2, by = "variable")
df2_wide <- df2_labeled %>%
pivot_wider(names_from = label, values_from = estimate, id_cols = NAME)
Exploratory Data Analysis (EDA)
# Ensure necessary libraries are installed and loaded
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("tidyr")) install.packages("tidyr")
library(ggplot2)
library(tidyr)
# Convert df2_wide to long format
df2_long <- df2_wide %>%
gather(key = "Education_Level", value = "Count", -NAME)
# Plotting the distribution of each education level across states
ggplot(df2_long, aes(x = NAME, y = Count, fill = Education_Level)) +
geom_bar(stat = "identity", position = position_dodge()) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = "Distribution of Education Levels across States",
x = "State",
y = "Count")
Exploratory Data Analysis (EDA) based on percentage
# Ensure necessary libraries are installed and loaded
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("tidyr")) install.packages("tidyr")
if (!require("dplyr")) install.packages("dplyr")
library(ggplot2)
library(tidyr)
library(dplyr)
# Convert df2_wide to long format
df2_long <- df2_wide %>%
gather(key = "Education_Level", value = "Count", -NAME)
# Calculate total count for each state
df2_long <- df2_long %>%
group_by(NAME) %>%
mutate(Total = sum(Count)) %>%
ungroup()
# Calculate the percentage
df2_long <- df2_long %>%
mutate(Percentage = (Count / Total) * 100)
# Plotting the distribution of each education level across states as a percentage
ggplot(df2_long, aes(x = NAME, y = Percentage, fill = Education_Level)) +
geom_bar(stat = "identity", position = position_dodge()) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = "Percentage Distribution of Education Levels across States",
x = "State",
y = "Percentage")
library(ggplot2)
library(tidyr)
library(dplyr)
# Convert df2_wide to long format
df2_long <- df2_wide %>%
gather(key = "Education_Level", value = "Count", -NAME)
# Calculate total count for each state only once
total_counts <- df2_long %>%
group_by(NAME) %>%
summarize(Total = sum(Count))
# Join with original data to add the Total column
df2_long <- df2_long %>%
left_join(total_counts, by = "NAME")
# Calculate the percentage for each education level
df2_long <- df2_long %>%
mutate(Percentage = (Count / Total) * 100)
# Create graphs for each educational level
unique_levels <- unique(df2_long$Education_Level)
plots <- list()
for (level in unique_levels) {
df_subset <- filter(df2_long, Education_Level == level)
p <- ggplot(df_subset, aes(x = NAME, y = Percentage, fill = Education_Level)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = paste("Percentage Distribution of", level, "across States"),
x = "State",
y = "Percentage") +
guides(fill = guide_legend(title = "Education Level"))
plots[[level]] <- p
}
# Print plots (optional)
for (plot in plots) {
print(plot)
}
df2_percentages <- df2_wide %>%
mutate(
`Education_Below_9th grade_Percentage` = `Education_Below_9th grade` / Education_Total_students * 100,
`Education_9th to 12th grade_no diploma_Percentage` = `Education_9th to 12th grade_no diploma` / Education_Total_students * 100,
Education_High_school_graduate_Percentage = Education_High_school_graduate / Education_Total_students * 100,
`Education_Some college_no degree_Percentage` = `Education_Some college_no degree` / Education_Total_students * 100,
Education_Associates_degree_Percentage = Education_Associates_degree / Education_Total_students * 100,
Education_Bachelors_degree_Percentage = Education_Bachelors_degree / Education_Total_students * 100,
`Education_Graduate_professional degree_Percentage` = `Education_Graduate_professional degree` / Education_Total_students * 100
)
percentage_columns <- grep("_Percentage$", names(df2_percentages), value = TRUE)
df2_long <- df2_percentages %>%
pivot_longer(cols = percentage_columns, names_to = "Age_Group", values_to = "Percentage")
## Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
## ℹ Please use `all_of()` or `any_of()` instead.
## # Was:
## data %>% select(percentage_columns)
##
## # Now:
## data %>% select(all_of(percentage_columns))
##
## See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ggplot(df2_long, aes(x = reorder(NAME, -Education_Total_students), y = Percentage, fill = Age_Group)) +
geom_bar(stat = "identity", position = "stack") +
labs(title = "Age Distribution by State",
x = "State",
y = "Percentage of Total Population",
fill = "Age Group") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
scale_fill_viridis_d() # Adjust the color scale as needed
#Esha
#Citizenship - K200501
df3<- get_acs(
geography = "state",
table = "K200501",
year = 2021,
survey = "acs1/subject",
cache_table = TRUE
)
## Getting data from the ACS 1-year Supplemental Estimates. Data are available for geographies with populations of 20,000 and greater.
## Loading ACSSE variables for 2021 from table K200501 and caching the dataset for faster future access.
variables_df3 <- data.frame(
variable = c("K200501_001", "K200501_002","K200501_003"),
label = c("Total","U.S. citizen", "Not a U.S. citizen")
)
df3_labeled <- df3 %>%
left_join(variables_df3, by = "variable")
df3_wide <- df3_labeled %>%
pivot_wider(names_from = label, values_from = estimate, id_cols = NAME)
# Load necessary libraries
library(ggplot2)
library(tidyr)
library(dplyr)
# Convert df3_wide to long format
df3_long <- df3_wide %>%
gather(key = "Citizenship", value = "Count", -NAME)
# Calculate total count for each state
df3_long <- df3_long %>%
group_by(NAME) %>%
mutate(Total = sum(Count)) %>%
ungroup()
# Calculate the percentage
df3_long <- df3_long %>%
mutate(Percentage = (Count / Total) * 100)
# Iterate over each unique citizenship category
for (category in unique(df3_long$Citizenship)) {
# Filter data for the current citizenship category
df3_subset <- df3_long %>%
filter(Citizenship == category)
# Generate and print the plot for citizenship
p <- ggplot(df3_subset, aes(x = NAME, y = Percentage, fill = Citizenship)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = paste("Percentage Distribution of", category, "across States"),
x = "State",
y = "Percentage")
print(p)
}
## Warning: Removed 1 rows containing missing values (`position_stack()`).
## Warning: Removed 1 rows containing missing values (`position_stack()`).
## Warning: Removed 1 rows containing missing values (`position_stack()`).
#Srika
#Age - K200104
df4 <- get_acs(geography = "state",
table = "K200104",
year = 2021,
survey = "acs1/subject",cache_table = TRUE
)
## Getting data from the ACS 1-year Supplemental Estimates. Data are available for geographies with populations of 20,000 and greater.
## Loading ACSSE variables for 2021 from table K200104 and caching the dataset for faster future access.
variables_df4 <- data.frame(
variable = c("K200104_001", "K200104_002", "K200104_003", "K200104_004", "K200104_005", "K200104_006", "K200104_007", "K200104_008"),
label = c("Total_age", "Age_under_18",
"Age_18_to_24", "Age_25_to_34",
"Age_35_to_44", "Age_45_to_54", "Age_55_to_64","Age_over_64")
)
df4_labeled <- df4 %>%
left_join(variables_df4, by = "variable")
df4_wide <- df4_labeled %>%
pivot_wider(names_from = label, values_from = estimate, id_cols = NAME)
df4_percentages <- df4_wide %>%
mutate(
Age_under_18_Percentage = Age_under_18 / Total_age * 100,
Age_18_to_24_Percentage = Age_18_to_24 / Total_age * 100,
Age_25_to_34_Percentage = Age_25_to_34 / Total_age * 100,
Age_35_to_44_Percentage = Age_35_to_44 / Total_age * 100,
Age_45_to_54_Percentage = Age_45_to_54 / Total_age * 100,
Age_55_to_64_Percentage = Age_55_to_64 / Total_age * 100,
Age_over_64_Percentage = Age_over_64 / Total_age * 100
)
percentage_columns <- grep("_Percentage$", names(df4_percentages), value = TRUE)
df4_long <- df4_percentages %>%
pivot_longer(cols = percentage_columns, names_to = "Age_Group", values_to = "Percentage")
ggplot(df4_long, aes(x = reorder(NAME, -Total_age), y = Percentage, fill = Age_Group)) +
geom_bar(stat = "identity", position = "stack") +
labs(title = "Age Distribution by State",
x = "State",
y = "Percentage of Total Population",
fill = "Age Group") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
scale_fill_viridis_d() # Adjust the color scale as needed
# Load necessary libraries if not already loaded
library(ggplot2)
library(tidyr)
# Calculate percentages for each age group
df4_percentages <- df4_wide %>%
mutate(
Age_under_18_Percentage = Age_under_18 / Total_age * 100,
Age_18_to_24_Percentage = Age_18_to_24 / Total_age * 100,
Age_25_to_34_Percentage = Age_25_to_34 / Total_age * 100,
Age_35_to_44_Percentage = Age_35_to_44 / Total_age * 100,
Age_45_to_54_Percentage = Age_45_to_54 / Total_age * 100,
Age_55_to_64_Percentage = Age_55_to_64 / Total_age * 100,
Age_over_64_Percentage = Age_over_64 / Total_age * 100
)
# Filter columns based on names ending with "Percentage"
percentage_columns <- grep("_Percentage$", names(df4_percentages), value = TRUE)
# Reshape the data to a longer format
df4_long <- df4_percentages %>%
pivot_longer(cols = percentage_columns, names_to = "Age_Group", values_to = "Percentage")
# Create a facet grid for each age group
ggplot(df4_long, aes(x = reorder(NAME, -Total_age), y = Percentage, fill = Age_Group)) +
geom_bar(stat = "identity", position = "stack") +
facet_grid(Age_Group ~ ., scales = "free_y") +
labs(title = "Age Distribution by State",
x = "State",
y = "Percentage of Total Population",
fill = "Age Group") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
scale_fill_viridis_d() # Adjust the color scale as needed
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.4
## ✔ lubridate 1.9.2 ✔ stringr 1.5.0
## ✔ purrr 1.0.2 ✔ tibble 3.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ purrr::map() masks maps::map()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tigris)
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
Age_data <- get_acs(geography = "state",
table = "K200104",
year = 2021,
geometry = TRUE,
resolution = "20m",
survey = "acs1/subject",cache_table = TRUE
)
## Getting data from the ACS 1-year Supplemental Estimates. Data are available for geographies with populations of 20,000 and greater.
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Loading ACSSE variables for 2021 from table K200104 and caching the dataset for faster future access.
##
|
| | 0%
|
|====== | 9%
|
|============ | 17%
|
|================== | 26%
|
|======================== | 35%
|
|=============================== | 44%
|
|===================================== | 52%
|
|=========================================== | 61%
|
|================================================= | 70%
|
|======================================================= | 79%
|
|============================================================= | 87%
|
|=================================================================== | 96%
|
|======================================================================| 100%
Mapping_age<-Age_data%>%
filter(variable=="K200104_007")%>%
shift_geometry()
ggplot(data = Mapping_age, aes(fill = estimate)) +
geom_sf()+
scale_fill_distiller(palette = "RdPu",
direction = 1) +
labs(title = "Median Age by State, 2021",
caption = "Data source: 2021 1-year ACS, US Census Bureau",
fill = "ACS estimate") +
theme_void()
#Niharika
# Housing - K202502
df5 <- get_acs(geography = "state",
table = "K202502",
year = 2021,
survey = "acs1", # removed /subject since we're referring to a specific table ID
cache_table = TRUE)
## Getting data from the 2021 1-year ACS
## The 1-year ACS provides data for geographies with populations of 65,000 and greater.
## Getting data from the ACS 1-year Supplemental Estimates. Data are available for geographies with populations of 20,000 and greater.
## Loading ACSSE variables for 2021 from table K202502 and caching the dataset for faster future access.
# Define the variable codes and their respective labels for the housing dataset (df5)
variables_df5 <- data.frame(
variable = c("K202502_001", "K202502_002", "K202502_003"),
label = c("Total", "Owner Occupied", "Renter Occupied")
)
# Assuming df5 is your housing dataset
# Reshape the data so that state names are rows
df5_labeled <- df5 %>%
left_join(variables_df5, by = "variable") # Joining with the variable labels dataframe
# Reshape the data to have state names as rows and variable labels as columns
df5_wide <- df5_labeled %>%
pivot_wider(names_from = label, values_from = estimate, id_cols = NAME)
# df5_wide will have states as rows and different housing-related variables as columns
library(dplyr)
library(tidyr)
library(ggplot2)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
# Assuming df5_wide is your dataset for housing
# Melt the data to long format for easy plotting
df5_long <- tidyr::gather(df5_wide, key = "Housing_Category", value = "Count", -NAME)
# Calculate the percentage for Owner and Renter Occupied categories
df5_long <- df5_long %>%
group_by(NAME) %>%
mutate(Total = sum(Count[which(Housing_Category == "Total")])) %>%
ungroup() %>%
mutate(Percentage = ifelse(Housing_Category != "Total", Count / Total * 100, Count))
# Define colors for each category
category_colors <- c("Owner Occupied" = "steelblue", "Renter Occupied" = "salmon", "Total" = "lightgreen")
# Function to create a bar plot
create_bar_plot <- function(data, category, title) {
ggplot(data[data$Housing_Category == category, ], aes(x = reorder(NAME, -Percentage), y = Percentage, fill = Housing_Category)) +
geom_bar(stat = "identity", position = position_dodge()) +
labs(x = "State", y = "Percentage", title = title) +
scale_y_continuous(labels = percent_format(scale = 1)) +
scale_fill_manual(values = category_colors) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
}
# Plot for Owner Occupied
owner_plot <- create_bar_plot(df5_long, "Owner Occupied", "Percentage of Owner Occupied Housing by State")
print(owner_plot)
# Plot for Renter Occupied
renter_plot <- create_bar_plot(df5_long, "Renter Occupied", "Percentage of Renter Occupied Housing by State")
print(renter_plot)
#install.packages("tidycensus")
# Load necessary libraries
library(tidycensus)
library(dplyr)
library(tidyr)
#install.packages("factoextra")
library(factoextra)
#install.packages("ggplot2")
#install.packages("usmap")
#install.packages("maps")
library(ggplot2)
library(usmap)
library(maps)
#Abhay
#Disabilities - K201803
# Get ACS data for the Disabilities dataset
df6 <- get_acs(geography = "state",
table = "K201803",
year = 2021,
survey = "acs1-year",
cache_table = TRUE)
## Getting data from the ACS 1-year Supplemental Estimates. Data are available for geographies with populations of 20,000 and greater.
## Loading ACSSE variables for 2021 from table K201803 and caching the dataset for faster future access.
# Assuming the variables_df6 mapping is similar to variables_df1 but for the Disabilities table
# You need to create variables_df6 with the correct variable codes and labels for the Disabilities data
variables_df6 <- data.frame(
variable = c("K201803_001", "K201803_002", "K201803_003", "K201803_004", "K201803_005", "K201803_006", "K201803_007","K201803_008","K201803_009"),
label = c("Total_people", "Total With Disabilities",
"Hearing", "Vision difficulty",
"cognative", "ambulatory difficulty",
"Self-care difficulty","Independent living difficulty","No Disability")
)
# Join your data with the variable labels to get the descriptive names
df6_labeled <- df6 %>%
left_join(variables_df6, by = "variable")
# Reshape the data so that state names are rows and variable labels are columns
df6_wide <- df6_labeled %>%
pivot_wider(names_from = label, values_from = estimate, id_cols = NAME)
df6_wide
## # A tibble: 52 × 10
## NAME Total_people Total With Disabilit…¹ Hearing `Vision difficulty`
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Alabama 4957633 808071 208028 152798
## 2 Alaska 702154 92390 33397 15748
## 3 Arizona 7174053 972252 298849 180792
## 4 Arkansas 2974701 517051 142133 105624
## 5 California 38724294 4324355 1140131 844049
## 6 Colorado 5715497 640346 211803 120570
## 7 Connecticut 3557526 427014 113490 78078
## 8 Delaware 987964 130551 37933 25335
## 9 District of … 659979 76754 14429 14569
## 10 Florida 21465883 2906367 812248 555361
## # ℹ 42 more rows
## # ℹ abbreviated name: ¹`Total With Disabilities`
## # ℹ 5 more variables: cognative <dbl>, `ambulatory difficulty` <dbl>,
## # `Self-care difficulty` <dbl>, `Independent living difficulty` <dbl>,
## # `No Disability` <dbl>
# df6_wide now has states as rows and the descriptive variable labels as columns
# Calculate percentages
df6_wide <- df6_wide %>%
mutate(DisabilityRate = `Total With Disabilities` / `Total_people` * 100)
# Plotting with ggplot2
library(ggplot2)
ggplot(df6_wide, aes(x = reorder(NAME, -DisabilityRate), y = DisabilityRate)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(x = "State", y = "Disability Rate (%)", title = "Disability Rates by State") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
# Select only the disability-related columns for correlation
disability_data <- df6_wide %>%
select(`Hearing`, `Vision difficulty`, `cognative`, `ambulatory difficulty`, `Self-care difficulty`, `Independent living difficulty`)
# Compute correlation matrix
correlation_matrix <- cor(disability_data, use = "complete.obs") # use = "complete.obs" handles missing values
# Check if corrplot is installed; if not, install it
if (!require(corrplot)) install.packages("corrplot")
library(corrplot)
corrplot(correlation_matrix, method = "circle")
# Comparative analysis of disabilities within a state (example: Iowa)
iowa_data <- df6_wide %>%
filter(NAME == "Iowa") %>%
select(`Hearing`, `Vision difficulty`, `cognative`, `ambulatory difficulty`, `Self-care difficulty`, `Independent living difficulty`)
# Plotting the data for Iowa
barplot(as.matrix(iowa_data), beside = TRUE, legend.text = TRUE, args.legend = list(x = "topright"))
# Predicting 'Ambulatory difficulty' based on other disabilities
lm_model <- lm(`ambulatory difficulty` ~ `Hearing` + `Vision difficulty` + `cognative` + `Self-care difficulty` + `Independent living difficulty`, data = df6_wide)
# Summary of the linear model
summary(lm_model)
##
## Call:
## lm(formula = `ambulatory difficulty` ~ Hearing + `Vision difficulty` +
## cognative + `Self-care difficulty` + `Independent living difficulty`,
## data = df6_wide)
##
## Residuals:
## Min 1Q Median 3Q Max
## -56621 -11941 -2766 17524 73868
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -8200.5856 5646.4977 -1.452 0.153197
## Hearing 0.6796 0.1793 3.791 0.000436 ***
## `Vision difficulty` 1.0070 0.1644 6.126 1.87e-07 ***
## cognative -0.5426 0.2291 -2.369 0.022116 *
## `Self-care difficulty` -1.9464 0.4434 -4.390 6.59e-05 ***
## `Independent living difficulty` 1.9228 0.3144 6.115 1.95e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 24940 on 46 degrees of freedom
## Multiple R-squared: 0.9968, Adjusted R-squared: 0.9965
## F-statistic: 2909 on 5 and 46 DF, p-value: < 2.2e-16
lm_model
##
## Call:
## lm(formula = `ambulatory difficulty` ~ Hearing + `Vision difficulty` +
## cognative + `Self-care difficulty` + `Independent living difficulty`,
## data = df6_wide)
##
## Coefficients:
## (Intercept) Hearing
## -8200.5856 0.6796
## `Vision difficulty` cognative
## 1.0070 -0.5426
## `Self-care difficulty` `Independent living difficulty`
## -1.9464 1.9228
# K-means clustering
#Perform a clustering analysis to identify groups of states with similar disability profiles.
# K-means clustering with 3 centers
set.seed(123) # For reproducibility
clusters <- kmeans(disability_data, centers = 3)
# Add cluster assignment to the data
df6_wide$Cluster <- as.factor(clusters$cluster)
pca_res <- prcomp(disability_data, scale. = TRUE)
fviz_pca_biplot(pca_res, label = "none", col.ind = df6_wide$Cluster, addEllipses = TRUE)
#census_api_key(Sys.getenv("CENSUS_API_KEY"), install = TRUE)
#install.packages("tidycensus")
# Load necessary libraries
library(tidycensus)
library(dplyr)
library(tidyr)
#install.packages("factoextra")
library(factoextra)
#install.packages("ggplot2")
#install.packages("usmap")
#install.packages("maps")
library(ggplot2)
library(usmap)
library(maps)
#install.packages("plotly")
merged_data <- df1_wide %>%
left_join(df2_wide, by = "NAME") %>%
left_join(df3_wide, by = "NAME")%>%
left_join(df4_wide, by = "NAME")%>%
left_join(df5_wide, by = "NAME")%>%
left_join(df6_wide, by = "NAME")
columns_to_drop <- c('Total.x', 'Total.y', 'Total.x.x', 'Total.y.y')
merged_data <- merged_data[, !(names(merged_data) %in% columns_to_drop)]
colnames(merged_data)
## [1] "NAME"
## [2] "In labor force:"
## [3] "Civilian labor force:"
## [4] "Employed"
## [5] "Unemployed"
## [6] "In Armed Forces"
## [7] "Not in labor force"
## [8] "EmploymentRate"
## [9] "UnemploymentRate"
## [10] "NotInLaborForceRate"
## [11] "state"
## [12] "Education_Total_students"
## [13] "Education_Below_9th grade"
## [14] "Education_9th to 12th grade_no diploma"
## [15] "Education_High_school_graduate"
## [16] "Education_Some college_no degree"
## [17] "Education_Associates_degree"
## [18] "Education_Bachelors_degree"
## [19] "Education_Graduate_professional degree"
## [20] "U.S. citizen"
## [21] "Not a U.S. citizen"
## [22] "Total_age"
## [23] "Age_under_18"
## [24] "Age_18_to_24"
## [25] "Age_25_to_34"
## [26] "Age_35_to_44"
## [27] "Age_45_to_54"
## [28] "Age_55_to_64"
## [29] "Age_over_64"
## [30] "Total"
## [31] "Owner Occupied"
## [32] "Renter Occupied"
## [33] "Total_people"
## [34] "Total With Disabilities"
## [35] "Hearing"
## [36] "Vision difficulty"
## [37] "cognative"
## [38] "ambulatory difficulty"
## [39] "Self-care difficulty"
## [40] "Independent living difficulty"
## [41] "No Disability"
## [42] "DisabilityRate"
## [43] "Cluster"
“Socio-Economic Factors Influencing Employment in the United States: A Comprehensive State-by-State Analysis”
This project aims to analyze the impact of various socio-economic factors such as education, age, citizenship status, housing, and disabilities on employment rates across different states in the United States. Using data from the American Community Survey (ACS) 2021, the study will employ statistical techniques to identify correlations, trends, and patterns, thereby providing insights into the multifaceted nature of employment dynamics in the US.
Data Exploration and Cleaning
Continue with data cleaning and handling missing values.
Normalize the data if required for better comparison.
#Check for Missing Values
# Checking the number of missing values in each column
summarize_missing_data <- function(data) {
sapply(data, function(x) sum(is.na(x)))
}
missing_data_summary <- summarize_missing_data(merged_data)
missing_data_summary
## NAME In labor force:
## 0 0
## Civilian labor force: Employed
## 0 0
## Unemployed In Armed Forces
## 0 0
## Not in labor force EmploymentRate
## 0 0
## UnemploymentRate NotInLaborForceRate
## 0 0
## state Education_Total_students
## 2 0
## Education_Below_9th grade Education_9th to 12th grade_no diploma
## 0 0
## Education_High_school_graduate Education_Some college_no degree
## 0 0
## Education_Associates_degree Education_Bachelors_degree
## 0 0
## Education_Graduate_professional degree U.S. citizen
## 0 1
## Not a U.S. citizen Total_age
## 1 0
## Age_under_18 Age_18_to_24
## 0 0
## Age_25_to_34 Age_35_to_44
## 0 0
## Age_45_to_54 Age_55_to_64
## 0 0
## Age_over_64 Total
## 0 0
## Owner Occupied Renter Occupied
## 0 0
## Total_people Total With Disabilities
## 0 0
## Hearing Vision difficulty
## 0 0
## cognative ambulatory difficulty
## 0 0
## Self-care difficulty Independent living difficulty
## 0 0
## No Disability DisabilityRate
## 0 0
## Cluster
## 0
# Handling missing values
handle_missing_values <- function(data) {
for (col in colnames(data)) {
if (is.numeric(data[[col]])) {
data[[col]] <- ifelse(is.na(data[[col]]), median(data[[col]], na.rm = TRUE), data[[col]])
}
# Add other conditions if needed for categorical data
}
return(data)
}
merged_data <- handle_missing_values(merged_data)
# Function to normalize only numeric columns
normalize_data <- function(data) {
for (col in colnames(data)) {
if (is.numeric(data[[col]])) {
min_val <- min(data[[col]], na.rm = TRUE)
max_val <- max(data[[col]], na.rm = TRUE)
data[[col]] <- (data[[col]] - min_val) / (max_val - min_val)
}
}
return(data)
}
# Apply the normalization function to the merged_data
normalized_data <- normalize_data(merged_data)
# Create a new dataset with only numeric columns
numeric_data <- normalized_data[sapply(normalized_data, is.numeric)]
# Compute the correlation matrix
correlation_matrix <- cor(numeric_data, use = "complete.obs")
# Use corrplot to visualize
library(corrplot)
corrplot(correlation_matrix, method = "circle")
# Example: Comparing Education and Employment Rates
ggplot(normalized_data, aes(x = `Education_Bachelors_degree`, y = EmploymentRate)) +
geom_point() +
geom_smooth(method = "lm") +
labs(title = "Relation between Bachelors Degree Holders and Employment Rate", x = "Percentage of Bachelor's Degree Holders", y = "Employment Rate")
## `geom_smooth()` using formula = 'y ~ x'
labs(title = "Relation between Bachelors Degree Holders and Employment Rate", x = "Percentage of Bachelors Degree Holders", y = "Employment Rate")
## $x
## [1] "Percentage of Bachelors Degree Holders"
##
## $y
## [1] "Employment Rate"
##
## $title
## [1] "Relation between Bachelors Degree Holders and Employment Rate"
##
## attr(,"class")
## [1] "labels"
numeric_columns <- sapply(merged_data, is.numeric)
numeric_data <- merged_data[, numeric_columns]
# Create a correlation matrix
correlation_matrix <- cor(numeric_data)
# Round the correlation matrix values
rounded_correlation_matrix <- round(correlation_matrix, digits = 2)
# Print the rounded correlation matrix
print(rounded_correlation_matrix)
## In labor force: Civilian labor force:
## In labor force: 1.00 1.00
## Civilian labor force: 1.00 1.00
## Employed 1.00 1.00
## Unemployed 0.97 0.98
## In Armed Forces 0.73 0.72
## Not in labor force 0.99 0.99
## EmploymentRate -0.03 -0.03
## UnemploymentRate 0.31 0.31
## NotInLaborForceRate -0.02 -0.02
## Education_Total_students 1.00 1.00
## Education_Below_9th grade 0.94 0.94
## Education_9th to 12th grade_no diploma 0.98 0.98
## Education_High_school_graduate 0.97 0.97
## Education_Some college_no degree 0.99 0.99
## Education_Associates_degree 0.98 0.98
## Education_Bachelors_degree 1.00 1.00
## Education_Graduate_professional degree 0.98 0.98
## U.S. citizen 1.00 1.00
## Not a U.S. citizen 0.95 0.95
## Total_age 1.00 1.00
## Age_under_18 0.99 0.99
## Age_18_to_24 1.00 1.00
## Age_25_to_34 1.00 1.00
## Age_35_to_44 1.00 1.00
## Age_45_to_54 1.00 1.00
## Age_55_to_64 0.99 1.00
## Age_over_64 0.98 0.98
## Total 1.00 1.00
## Owner Occupied 0.98 0.98
## Renter Occupied 0.99 0.99
## Total_people 1.00 1.00
## Total With Disabilities 0.99 0.99
## Hearing 0.98 0.98
## Vision difficulty 0.97 0.97
## cognative 0.99 0.99
## ambulatory difficulty 0.98 0.98
## Self-care difficulty 0.99 0.99
## Independent living difficulty 0.99 0.99
## No Disability 1.00 1.00
## DisabilityRate -0.29 -0.29
## Employed Unemployed In Armed Forces
## In labor force: 1.00 0.97 0.73
## Civilian labor force: 1.00 0.98 0.72
## Employed 1.00 0.97 0.73
## Unemployed 0.97 1.00 0.68
## In Armed Forces 0.73 0.68 1.00
## Not in labor force 0.99 0.97 0.72
## EmploymentRate -0.02 -0.09 -0.05
## UnemploymentRate 0.30 0.42 0.17
## NotInLaborForceRate -0.02 0.02 -0.04
## Education_Total_students 1.00 0.97 0.72
## Education_Below_9th grade 0.94 0.97 0.71
## Education_9th to 12th grade_no diploma 0.98 0.97 0.74
## Education_High_school_graduate 0.98 0.93 0.66
## Education_Some college_no degree 0.99 0.96 0.75
## Education_Associates_degree 0.98 0.95 0.70
## Education_Bachelors_degree 1.00 0.98 0.73
## Education_Graduate_professional degree 0.98 0.98 0.71
## U.S. citizen 1.00 0.97 0.72
## Not a U.S. citizen 0.95 0.97 0.72
## Total_age 1.00 0.97 0.73
## Age_under_18 0.99 0.96 0.74
## Age_18_to_24 1.00 0.97 0.74
## Age_25_to_34 1.00 0.98 0.74
## Age_35_to_44 1.00 0.97 0.74
## Age_45_to_54 1.00 0.98 0.73
## Age_55_to_64 0.99 0.97 0.70
## Age_over_64 0.98 0.95 0.68
## Total 1.00 0.96 0.71
## Owner Occupied 0.98 0.93 0.70
## Renter Occupied 0.99 0.99 0.72
## Total_people 1.00 0.97 0.73
## Total With Disabilities 0.99 0.95 0.71
## Hearing 0.98 0.93 0.72
## Vision difficulty 0.97 0.94 0.73
## cognative 0.99 0.95 0.71
## ambulatory difficulty 0.98 0.95 0.71
## Self-care difficulty 0.99 0.98 0.71
## Independent living difficulty 0.99 0.97 0.70
## No Disability 1.00 0.98 0.73
## DisabilityRate -0.29 -0.26 -0.24
## Not in labor force EmploymentRate
## In labor force: 0.99 -0.03
## Civilian labor force: 0.99 -0.03
## Employed 0.99 -0.02
## Unemployed 0.97 -0.09
## In Armed Forces 0.72 -0.05
## Not in labor force 1.00 -0.11
## EmploymentRate -0.11 1.00
## UnemploymentRate 0.32 -0.45
## NotInLaborForceRate 0.07 -0.96
## Education_Total_students 1.00 -0.06
## Education_Below_9th grade 0.93 -0.10
## Education_9th to 12th grade_no diploma 0.99 -0.13
## Education_High_school_graduate 0.98 -0.10
## Education_Some college_no degree 0.99 -0.05
## Education_Associates_degree 0.99 -0.08
## Education_Bachelors_degree 0.99 -0.02
## Education_Graduate_professional degree 0.97 -0.01
## U.S. citizen 1.00 -0.07
## Not a U.S. citizen 0.94 -0.03
## Total_age 1.00 -0.05
## Age_under_18 0.98 -0.03
## Age_18_to_24 0.99 -0.04
## Age_25_to_34 0.99 -0.04
## Age_35_to_44 0.99 -0.04
## Age_45_to_54 1.00 -0.06
## Age_55_to_64 1.00 -0.07
## Age_over_64 0.99 -0.10
## Total 0.99 -0.05
## Owner Occupied 0.98 -0.05
## Renter Occupied 0.99 -0.05
## Total_people 1.00 -0.05
## Total With Disabilities 1.00 -0.13
## Hearing 0.99 -0.11
## Vision difficulty 0.98 -0.18
## cognative 0.99 -0.13
## ambulatory difficulty 0.99 -0.16
## Self-care difficulty 1.00 -0.16
## Independent living difficulty 1.00 -0.15
## No Disability 0.99 -0.04
## DisabilityRate -0.21 -0.80
## UnemploymentRate NotInLaborForceRate
## In labor force: 0.31 -0.02
## Civilian labor force: 0.31 -0.02
## Employed 0.30 -0.02
## Unemployed 0.42 0.02
## In Armed Forces 0.17 -0.04
## Not in labor force 0.32 0.07
## EmploymentRate -0.45 -0.96
## UnemploymentRate 1.00 0.22
## NotInLaborForceRate 0.22 1.00
## Education_Total_students 0.32 0.02
## Education_Below_9th grade 0.35 0.04
## Education_9th to 12th grade_no diploma 0.32 0.09
## Education_High_school_graduate 0.29 0.07
## Education_Some college_no degree 0.28 0.01
## Education_Associates_degree 0.29 0.05
## Education_Bachelors_degree 0.33 -0.03
## Education_Graduate_professional degree 0.37 -0.05
## U.S. citizen 0.31 0.03
## Not a U.S. citizen 0.34 -0.04
## Total_age 0.31 0.01
## Age_under_18 0.29 -0.01
## Age_18_to_24 0.30 0.00
## Age_25_to_34 0.32 -0.01
## Age_35_to_44 0.31 -0.01
## Age_45_to_54 0.32 0.01
## Age_55_to_64 0.32 0.02
## Age_over_64 0.31 0.06
## Total 0.31 0.01
## Owner Occupied 0.28 0.02
## Renter Occupied 0.34 -0.01
## Total_people 0.31 0.01
## Total With Disabilities 0.31 0.10
## Hearing 0.27 0.08
## Vision difficulty 0.32 0.14
## cognative 0.31 0.10
## ambulatory difficulty 0.32 0.13
## Self-care difficulty 0.35 0.11
## Independent living difficulty 0.34 0.11
## No Disability 0.31 0.00
## DisabilityRate 0.03 0.87
## Education_Total_students
## In labor force: 1.00
## Civilian labor force: 1.00
## Employed 1.00
## Unemployed 0.97
## In Armed Forces 0.72
## Not in labor force 1.00
## EmploymentRate -0.06
## UnemploymentRate 0.32
## NotInLaborForceRate 0.02
## Education_Total_students 1.00
## Education_Below_9th grade 0.94
## Education_9th to 12th grade_no diploma 0.99
## Education_High_school_graduate 0.98
## Education_Some college_no degree 0.99
## Education_Associates_degree 0.99
## Education_Bachelors_degree 1.00
## Education_Graduate_professional degree 0.98
## U.S. citizen 1.00
## Not a U.S. citizen 0.95
## Total_age 1.00
## Age_under_18 0.99
## Age_18_to_24 0.99
## Age_25_to_34 1.00
## Age_35_to_44 1.00
## Age_45_to_54 1.00
## Age_55_to_64 1.00
## Age_over_64 0.99
## Total 1.00
## Owner Occupied 0.98
## Renter Occupied 0.99
## Total_people 1.00
## Total With Disabilities 0.99
## Hearing 0.99
## Vision difficulty 0.98
## cognative 0.99
## ambulatory difficulty 0.99
## Self-care difficulty 0.99
## Independent living difficulty 0.99
## No Disability 1.00
## DisabilityRate -0.26
## Education_Below_9th grade
## In labor force: 0.94
## Civilian labor force: 0.94
## Employed 0.94
## Unemployed 0.97
## In Armed Forces 0.71
## Not in labor force 0.93
## EmploymentRate -0.10
## UnemploymentRate 0.35
## NotInLaborForceRate 0.04
## Education_Total_students 0.94
## Education_Below_9th grade 1.00
## Education_9th to 12th grade_no diploma 0.96
## Education_High_school_graduate 0.87
## Education_Some college_no degree 0.94
## Education_Associates_degree 0.90
## Education_Bachelors_degree 0.94
## Education_Graduate_professional degree 0.92
## U.S. citizen 0.93
## Not a U.S. citizen 0.99
## Total_age 0.94
## Age_under_18 0.95
## Age_18_to_24 0.95
## Age_25_to_34 0.96
## Age_35_to_44 0.96
## Age_45_to_54 0.95
## Age_55_to_64 0.92
## Age_over_64 0.90
## Total 0.92
## Owner Occupied 0.88
## Renter Occupied 0.96
## Total_people 0.94
## Total With Disabilities 0.91
## Hearing 0.91
## Vision difficulty 0.93
## cognative 0.92
## ambulatory difficulty 0.91
## Self-care difficulty 0.95
## Independent living difficulty 0.93
## No Disability 0.95
## DisabilityRate -0.20
## Education_9th to 12th grade_no diploma
## In labor force: 0.98
## Civilian labor force: 0.98
## Employed 0.98
## Unemployed 0.97
## In Armed Forces 0.74
## Not in labor force 0.99
## EmploymentRate -0.13
## UnemploymentRate 0.32
## NotInLaborForceRate 0.09
## Education_Total_students 0.99
## Education_Below_9th grade 0.96
## Education_9th to 12th grade_no diploma 1.00
## Education_High_school_graduate 0.96
## Education_Some college_no degree 0.98
## Education_Associates_degree 0.96
## Education_Bachelors_degree 0.97
## Education_Graduate_professional degree 0.95
## U.S. citizen 0.99
## Not a U.S. citizen 0.95
## Total_age 0.99
## Age_under_18 0.99
## Age_18_to_24 0.99
## Age_25_to_34 0.99
## Age_35_to_44 0.99
## Age_45_to_54 0.99
## Age_55_to_64 0.98
## Age_over_64 0.96
## Total 0.98
## Owner Occupied 0.96
## Renter Occupied 0.98
## Total_people 0.99
## Total With Disabilities 0.98
## Hearing 0.98
## Vision difficulty 0.99
## cognative 0.98
## ambulatory difficulty 0.98
## Self-care difficulty 0.99
## Independent living difficulty 0.99
## No Disability 0.99
## DisabilityRate -0.18
## Education_High_school_graduate
## In labor force: 0.97
## Civilian labor force: 0.97
## Employed 0.98
## Unemployed 0.93
## In Armed Forces 0.66
## Not in labor force 0.98
## EmploymentRate -0.10
## UnemploymentRate 0.29
## NotInLaborForceRate 0.07
## Education_Total_students 0.98
## Education_Below_9th grade 0.87
## Education_9th to 12th grade_no diploma 0.96
## Education_High_school_graduate 1.00
## Education_Some college_no degree 0.96
## Education_Associates_degree 0.98
## Education_Bachelors_degree 0.96
## Education_Graduate_professional degree 0.94
## U.S. citizen 0.98
## Not a U.S. citizen 0.87
## Total_age 0.98
## Age_under_18 0.97
## Age_18_to_24 0.97
## Age_25_to_34 0.96
## Age_35_to_44 0.97
## Age_45_to_54 0.98
## Age_55_to_64 0.99
## Age_over_64 0.99
## Total 0.99
## Owner Occupied 0.99
## Renter Occupied 0.96
## Total_people 0.98
## Total With Disabilities 0.99
## Hearing 0.99
## Vision difficulty 0.97
## cognative 0.99
## ambulatory difficulty 0.99
## Self-care difficulty 0.97
## Independent living difficulty 0.98
## No Disability 0.97
## DisabilityRate -0.20
## Education_Some college_no degree
## In labor force: 0.99
## Civilian labor force: 0.99
## Employed 0.99
## Unemployed 0.96
## In Armed Forces 0.75
## Not in labor force 0.99
## EmploymentRate -0.05
## UnemploymentRate 0.28
## NotInLaborForceRate 0.01
## Education_Total_students 0.99
## Education_Below_9th grade 0.94
## Education_9th to 12th grade_no diploma 0.98
## Education_High_school_graduate 0.96
## Education_Some college_no degree 1.00
## Education_Associates_degree 0.98
## Education_Bachelors_degree 0.98
## Education_Graduate_professional degree 0.95
## U.S. citizen 0.99
## Not a U.S. citizen 0.94
## Total_age 0.99
## Age_under_18 0.99
## Age_18_to_24 0.99
## Age_25_to_34 0.99
## Age_35_to_44 0.99
## Age_45_to_54 0.99
## Age_55_to_64 0.98
## Age_over_64 0.97
## Total 0.99
## Owner Occupied 0.98
## Renter Occupied 0.98
## Total_people 0.99
## Total With Disabilities 0.98
## Hearing 0.99
## Vision difficulty 0.97
## cognative 0.98
## ambulatory difficulty 0.98
## Self-care difficulty 0.98
## Independent living difficulty 0.98
## No Disability 0.99
## DisabilityRate -0.25
## Education_Associates_degree
## In labor force: 0.98
## Civilian labor force: 0.98
## Employed 0.98
## Unemployed 0.95
## In Armed Forces 0.70
## Not in labor force 0.99
## EmploymentRate -0.08
## UnemploymentRate 0.29
## NotInLaborForceRate 0.05
## Education_Total_students 0.99
## Education_Below_9th grade 0.90
## Education_9th to 12th grade_no diploma 0.96
## Education_High_school_graduate 0.98
## Education_Some college_no degree 0.98
## Education_Associates_degree 1.00
## Education_Bachelors_degree 0.98
## Education_Graduate_professional degree 0.96
## U.S. citizen 0.99
## Not a U.S. citizen 0.91
## Total_age 0.98
## Age_under_18 0.97
## Age_18_to_24 0.97
## Age_25_to_34 0.97
## Age_35_to_44 0.97
## Age_45_to_54 0.98
## Age_55_to_64 0.99
## Age_over_64 0.99
## Total 0.99
## Owner Occupied 0.98
## Renter Occupied 0.97
## Total_people 0.98
## Total With Disabilities 0.99
## Hearing 0.98
## Vision difficulty 0.96
## cognative 0.98
## ambulatory difficulty 0.98
## Self-care difficulty 0.98
## Independent living difficulty 0.99
## No Disability 0.98
## DisabilityRate -0.24
## Education_Bachelors_degree
## In labor force: 1.00
## Civilian labor force: 1.00
## Employed 1.00
## Unemployed 0.98
## In Armed Forces 0.73
## Not in labor force 0.99
## EmploymentRate -0.02
## UnemploymentRate 0.33
## NotInLaborForceRate -0.03
## Education_Total_students 1.00
## Education_Below_9th grade 0.94
## Education_9th to 12th grade_no diploma 0.97
## Education_High_school_graduate 0.96
## Education_Some college_no degree 0.98
## Education_Associates_degree 0.98
## Education_Bachelors_degree 1.00
## Education_Graduate_professional degree 0.99
## U.S. citizen 0.99
## Not a U.S. citizen 0.95
## Total_age 0.99
## Age_under_18 0.98
## Age_18_to_24 0.99
## Age_25_to_34 0.99
## Age_35_to_44 0.99
## Age_45_to_54 1.00
## Age_55_to_64 0.99
## Age_over_64 0.98
## Total 0.99
## Owner Occupied 0.97
## Renter Occupied 0.99
## Total_people 0.99
## Total With Disabilities 0.98
## Hearing 0.97
## Vision difficulty 0.96
## cognative 0.98
## ambulatory difficulty 0.97
## Self-care difficulty 0.98
## Independent living difficulty 0.98
## No Disability 1.00
## DisabilityRate -0.31
## Education_Graduate_professional degree
## In labor force: 0.98
## Civilian labor force: 0.98
## Employed 0.98
## Unemployed 0.98
## In Armed Forces 0.71
## Not in labor force 0.97
## EmploymentRate -0.01
## UnemploymentRate 0.37
## NotInLaborForceRate -0.05
## Education_Total_students 0.98
## Education_Below_9th grade 0.92
## Education_9th to 12th grade_no diploma 0.95
## Education_High_school_graduate 0.94
## Education_Some college_no degree 0.95
## Education_Associates_degree 0.96
## Education_Bachelors_degree 0.99
## Education_Graduate_professional degree 1.00
## U.S. citizen 0.97
## Not a U.S. citizen 0.93
## Total_age 0.98
## Age_under_18 0.96
## Age_18_to_24 0.97
## Age_25_to_34 0.97
## Age_35_to_44 0.97
## Age_45_to_54 0.98
## Age_55_to_64 0.98
## Age_over_64 0.97
## Total 0.97
## Owner Occupied 0.95
## Renter Occupied 0.98
## Total_people 0.98
## Total With Disabilities 0.95
## Hearing 0.94
## Vision difficulty 0.93
## cognative 0.95
## ambulatory difficulty 0.95
## Self-care difficulty 0.97
## Independent living difficulty 0.97
## No Disability 0.98
## DisabilityRate -0.34
## U.S. citizen Not a U.S. citizen
## In labor force: 1.00 0.95
## Civilian labor force: 1.00 0.95
## Employed 1.00 0.95
## Unemployed 0.97 0.97
## In Armed Forces 0.72 0.72
## Not in labor force 1.00 0.94
## EmploymentRate -0.07 -0.03
## UnemploymentRate 0.31 0.34
## NotInLaborForceRate 0.03 -0.04
## Education_Total_students 1.00 0.95
## Education_Below_9th grade 0.93 0.99
## Education_9th to 12th grade_no diploma 0.99 0.95
## Education_High_school_graduate 0.98 0.87
## Education_Some college_no degree 0.99 0.94
## Education_Associates_degree 0.99 0.91
## Education_Bachelors_degree 0.99 0.95
## Education_Graduate_professional degree 0.97 0.93
## U.S. citizen 1.00 0.94
## Not a U.S. citizen 0.94 1.00
## Total_age 1.00 0.95
## Age_under_18 0.99 0.95
## Age_18_to_24 1.00 0.95
## Age_25_to_34 0.99 0.96
## Age_35_to_44 1.00 0.96
## Age_45_to_54 1.00 0.95
## Age_55_to_64 1.00 0.93
## Age_over_64 0.98 0.91
## Total 1.00 0.93
## Owner Occupied 0.99 0.88
## Renter Occupied 0.99 0.96
## Total_people 1.00 0.95
## Total With Disabilities 0.99 0.91
## Hearing 0.99 0.91
## Vision difficulty 0.98 0.91
## cognative 0.99 0.91
## ambulatory difficulty 0.99 0.91
## Self-care difficulty 0.99 0.94
## Independent living difficulty 0.99 0.93
## No Disability 1.00 0.95
## DisabilityRate -0.24 -0.30
## Total_age Age_under_18 Age_18_to_24
## In labor force: 1.00 0.99 1.00
## Civilian labor force: 1.00 0.99 1.00
## Employed 1.00 0.99 1.00
## Unemployed 0.97 0.96 0.97
## In Armed Forces 0.73 0.74 0.74
## Not in labor force 1.00 0.98 0.99
## EmploymentRate -0.05 -0.03 -0.04
## UnemploymentRate 0.31 0.29 0.30
## NotInLaborForceRate 0.01 -0.01 0.00
## Education_Total_students 1.00 0.99 0.99
## Education_Below_9th grade 0.94 0.95 0.95
## Education_9th to 12th grade_no diploma 0.99 0.99 0.99
## Education_High_school_graduate 0.98 0.97 0.97
## Education_Some college_no degree 0.99 0.99 0.99
## Education_Associates_degree 0.98 0.97 0.97
## Education_Bachelors_degree 0.99 0.98 0.99
## Education_Graduate_professional degree 0.98 0.96 0.97
## U.S. citizen 1.00 0.99 1.00
## Not a U.S. citizen 0.95 0.95 0.95
## Total_age 1.00 0.99 1.00
## Age_under_18 0.99 1.00 1.00
## Age_18_to_24 1.00 1.00 1.00
## Age_25_to_34 1.00 1.00 1.00
## Age_35_to_44 1.00 1.00 1.00
## Age_45_to_54 1.00 0.99 1.00
## Age_55_to_64 1.00 0.98 0.99
## Age_over_64 0.98 0.96 0.97
## Total 1.00 0.99 0.99
## Owner Occupied 0.98 0.98 0.98
## Renter Occupied 0.99 0.99 0.99
## Total_people 1.00 0.99 1.00
## Total With Disabilities 0.99 0.98 0.99
## Hearing 0.99 0.98 0.98
## Vision difficulty 0.98 0.98 0.98
## cognative 0.99 0.98 0.99
## ambulatory difficulty 0.99 0.98 0.98
## Self-care difficulty 0.99 0.98 0.98
## Independent living difficulty 0.99 0.98 0.98
## No Disability 1.00 1.00 1.00
## DisabilityRate -0.26 -0.27 -0.26
## Age_25_to_34 Age_35_to_44 Age_45_to_54
## In labor force: 1.00 1.00 1.00
## Civilian labor force: 1.00 1.00 1.00
## Employed 1.00 1.00 1.00
## Unemployed 0.98 0.97 0.98
## In Armed Forces 0.74 0.74 0.73
## Not in labor force 0.99 0.99 1.00
## EmploymentRate -0.04 -0.04 -0.06
## UnemploymentRate 0.32 0.31 0.32
## NotInLaborForceRate -0.01 -0.01 0.01
## Education_Total_students 1.00 1.00 1.00
## Education_Below_9th grade 0.96 0.96 0.95
## Education_9th to 12th grade_no diploma 0.99 0.99 0.99
## Education_High_school_graduate 0.96 0.97 0.98
## Education_Some college_no degree 0.99 0.99 0.99
## Education_Associates_degree 0.97 0.97 0.98
## Education_Bachelors_degree 0.99 0.99 1.00
## Education_Graduate_professional degree 0.97 0.97 0.98
## U.S. citizen 0.99 1.00 1.00
## Not a U.S. citizen 0.96 0.96 0.95
## Total_age 1.00 1.00 1.00
## Age_under_18 1.00 1.00 0.99
## Age_18_to_24 1.00 1.00 1.00
## Age_25_to_34 1.00 1.00 1.00
## Age_35_to_44 1.00 1.00 1.00
## Age_45_to_54 1.00 1.00 1.00
## Age_55_to_64 0.99 0.99 1.00
## Age_over_64 0.97 0.97 0.98
## Total 0.99 0.99 1.00
## Owner Occupied 0.97 0.98 0.98
## Renter Occupied 0.99 0.99 0.99
## Total_people 1.00 1.00 1.00
## Total With Disabilities 0.98 0.98 0.99
## Hearing 0.98 0.98 0.98
## Vision difficulty 0.97 0.98 0.98
## cognative 0.98 0.98 0.99
## ambulatory difficulty 0.98 0.98 0.99
## Self-care difficulty 0.99 0.99 0.99
## Independent living difficulty 0.98 0.98 0.99
## No Disability 1.00 1.00 1.00
## DisabilityRate -0.27 -0.27 -0.26
## Age_55_to_64 Age_over_64 Total
## In labor force: 0.99 0.98 1.00
## Civilian labor force: 1.00 0.98 1.00
## Employed 0.99 0.98 1.00
## Unemployed 0.97 0.95 0.96
## In Armed Forces 0.70 0.68 0.71
## Not in labor force 1.00 0.99 0.99
## EmploymentRate -0.07 -0.10 -0.05
## UnemploymentRate 0.32 0.31 0.31
## NotInLaborForceRate 0.02 0.06 0.01
## Education_Total_students 1.00 0.99 1.00
## Education_Below_9th grade 0.92 0.90 0.92
## Education_9th to 12th grade_no diploma 0.98 0.96 0.98
## Education_High_school_graduate 0.99 0.99 0.99
## Education_Some college_no degree 0.98 0.97 0.99
## Education_Associates_degree 0.99 0.99 0.99
## Education_Bachelors_degree 0.99 0.98 0.99
## Education_Graduate_professional degree 0.98 0.97 0.97
## U.S. citizen 1.00 0.98 1.00
## Not a U.S. citizen 0.93 0.91 0.93
## Total_age 1.00 0.98 1.00
## Age_under_18 0.98 0.96 0.99
## Age_18_to_24 0.99 0.97 0.99
## Age_25_to_34 0.99 0.97 0.99
## Age_35_to_44 0.99 0.97 0.99
## Age_45_to_54 1.00 0.98 1.00
## Age_55_to_64 1.00 0.99 1.00
## Age_over_64 0.99 1.00 0.99
## Total 1.00 0.99 1.00
## Owner Occupied 0.99 0.98 0.99
## Renter Occupied 0.99 0.97 0.99
## Total_people 1.00 0.98 1.00
## Total With Disabilities 0.99 0.99 0.99
## Hearing 0.98 0.98 0.99
## Vision difficulty 0.97 0.96 0.98
## cognative 0.99 0.98 0.99
## ambulatory difficulty 0.99 0.99 0.99
## Self-care difficulty 0.99 0.98 0.99
## Independent living difficulty 0.99 0.99 0.99
## No Disability 0.99 0.98 1.00
## DisabilityRate -0.26 -0.23 -0.26
## Owner Occupied Renter Occupied
## In labor force: 0.98 0.99
## Civilian labor force: 0.98 0.99
## Employed 0.98 0.99
## Unemployed 0.93 0.99
## In Armed Forces 0.70 0.72
## Not in labor force 0.98 0.99
## EmploymentRate -0.05 -0.05
## UnemploymentRate 0.28 0.34
## NotInLaborForceRate 0.02 -0.01
## Education_Total_students 0.98 0.99
## Education_Below_9th grade 0.88 0.96
## Education_9th to 12th grade_no diploma 0.96 0.98
## Education_High_school_graduate 0.99 0.96
## Education_Some college_no degree 0.98 0.98
## Education_Associates_degree 0.98 0.97
## Education_Bachelors_degree 0.97 0.99
## Education_Graduate_professional degree 0.95 0.98
## U.S. citizen 0.99 0.99
## Not a U.S. citizen 0.88 0.96
## Total_age 0.98 0.99
## Age_under_18 0.98 0.99
## Age_18_to_24 0.98 0.99
## Age_25_to_34 0.97 0.99
## Age_35_to_44 0.98 0.99
## Age_45_to_54 0.98 0.99
## Age_55_to_64 0.99 0.99
## Age_over_64 0.98 0.97
## Total 0.99 0.99
## Owner Occupied 1.00 0.96
## Renter Occupied 0.96 1.00
## Total_people 0.98 0.99
## Total With Disabilities 0.99 0.98
## Hearing 0.99 0.97
## Vision difficulty 0.97 0.96
## cognative 0.99 0.98
## ambulatory difficulty 0.99 0.97
## Self-care difficulty 0.97 0.99
## Independent living difficulty 0.98 0.98
## No Disability 0.98 0.99
## DisabilityRate -0.25 -0.27
## Total_people Total With Disabilities
## In labor force: 1.00 0.99
## Civilian labor force: 1.00 0.99
## Employed 1.00 0.99
## Unemployed 0.97 0.95
## In Armed Forces 0.73 0.71
## Not in labor force 1.00 1.00
## EmploymentRate -0.05 -0.13
## UnemploymentRate 0.31 0.31
## NotInLaborForceRate 0.01 0.10
## Education_Total_students 1.00 0.99
## Education_Below_9th grade 0.94 0.91
## Education_9th to 12th grade_no diploma 0.99 0.98
## Education_High_school_graduate 0.98 0.99
## Education_Some college_no degree 0.99 0.98
## Education_Associates_degree 0.98 0.99
## Education_Bachelors_degree 0.99 0.98
## Education_Graduate_professional degree 0.98 0.95
## U.S. citizen 1.00 0.99
## Not a U.S. citizen 0.95 0.91
## Total_age 1.00 0.99
## Age_under_18 0.99 0.98
## Age_18_to_24 1.00 0.99
## Age_25_to_34 1.00 0.98
## Age_35_to_44 1.00 0.98
## Age_45_to_54 1.00 0.99
## Age_55_to_64 1.00 0.99
## Age_over_64 0.98 0.99
## Total 1.00 0.99
## Owner Occupied 0.98 0.99
## Renter Occupied 0.99 0.98
## Total_people 1.00 0.99
## Total With Disabilities 0.99 1.00
## Hearing 0.99 1.00
## Vision difficulty 0.98 0.99
## cognative 0.99 1.00
## ambulatory difficulty 0.99 1.00
## Self-care difficulty 0.99 0.99
## Independent living difficulty 0.99 0.99
## No Disability 1.00 0.99
## DisabilityRate -0.26 -0.17
## Hearing Vision difficulty cognative
## In labor force: 0.98 0.97 0.99
## Civilian labor force: 0.98 0.97 0.99
## Employed 0.98 0.97 0.99
## Unemployed 0.93 0.94 0.95
## In Armed Forces 0.72 0.73 0.71
## Not in labor force 0.99 0.98 0.99
## EmploymentRate -0.11 -0.18 -0.13
## UnemploymentRate 0.27 0.32 0.31
## NotInLaborForceRate 0.08 0.14 0.10
## Education_Total_students 0.99 0.98 0.99
## Education_Below_9th grade 0.91 0.93 0.92
## Education_9th to 12th grade_no diploma 0.98 0.99 0.98
## Education_High_school_graduate 0.99 0.97 0.99
## Education_Some college_no degree 0.99 0.97 0.98
## Education_Associates_degree 0.98 0.96 0.98
## Education_Bachelors_degree 0.97 0.96 0.98
## Education_Graduate_professional degree 0.94 0.93 0.95
## U.S. citizen 0.99 0.98 0.99
## Not a U.S. citizen 0.91 0.91 0.91
## Total_age 0.99 0.98 0.99
## Age_under_18 0.98 0.98 0.98
## Age_18_to_24 0.98 0.98 0.99
## Age_25_to_34 0.98 0.97 0.98
## Age_35_to_44 0.98 0.98 0.98
## Age_45_to_54 0.98 0.98 0.99
## Age_55_to_64 0.98 0.97 0.99
## Age_over_64 0.98 0.96 0.98
## Total 0.99 0.98 0.99
## Owner Occupied 0.99 0.97 0.99
## Renter Occupied 0.97 0.96 0.98
## Total_people 0.99 0.98 0.99
## Total With Disabilities 1.00 0.99 1.00
## Hearing 1.00 0.99 1.00
## Vision difficulty 0.99 1.00 0.99
## cognative 1.00 0.99 1.00
## ambulatory difficulty 0.99 0.99 1.00
## Self-care difficulty 0.98 0.98 0.99
## Independent living difficulty 0.98 0.98 0.99
## No Disability 0.98 0.98 0.99
## DisabilityRate -0.18 -0.11 -0.16
## ambulatory difficulty
## In labor force: 0.98
## Civilian labor force: 0.98
## Employed 0.98
## Unemployed 0.95
## In Armed Forces 0.71
## Not in labor force 0.99
## EmploymentRate -0.16
## UnemploymentRate 0.32
## NotInLaborForceRate 0.13
## Education_Total_students 0.99
## Education_Below_9th grade 0.91
## Education_9th to 12th grade_no diploma 0.98
## Education_High_school_graduate 0.99
## Education_Some college_no degree 0.98
## Education_Associates_degree 0.98
## Education_Bachelors_degree 0.97
## Education_Graduate_professional degree 0.95
## U.S. citizen 0.99
## Not a U.S. citizen 0.91
## Total_age 0.99
## Age_under_18 0.98
## Age_18_to_24 0.98
## Age_25_to_34 0.98
## Age_35_to_44 0.98
## Age_45_to_54 0.99
## Age_55_to_64 0.99
## Age_over_64 0.99
## Total 0.99
## Owner Occupied 0.99
## Renter Occupied 0.97
## Total_people 0.99
## Total With Disabilities 1.00
## Hearing 0.99
## Vision difficulty 0.99
## cognative 1.00
## ambulatory difficulty 1.00
## Self-care difficulty 0.99
## Independent living difficulty 0.99
## No Disability 0.98
## DisabilityRate -0.14
## Self-care difficulty
## In labor force: 0.99
## Civilian labor force: 0.99
## Employed 0.99
## Unemployed 0.98
## In Armed Forces 0.71
## Not in labor force 1.00
## EmploymentRate -0.16
## UnemploymentRate 0.35
## NotInLaborForceRate 0.11
## Education_Total_students 0.99
## Education_Below_9th grade 0.95
## Education_9th to 12th grade_no diploma 0.99
## Education_High_school_graduate 0.97
## Education_Some college_no degree 0.98
## Education_Associates_degree 0.98
## Education_Bachelors_degree 0.98
## Education_Graduate_professional degree 0.97
## U.S. citizen 0.99
## Not a U.S. citizen 0.94
## Total_age 0.99
## Age_under_18 0.98
## Age_18_to_24 0.98
## Age_25_to_34 0.99
## Age_35_to_44 0.99
## Age_45_to_54 0.99
## Age_55_to_64 0.99
## Age_over_64 0.98
## Total 0.99
## Owner Occupied 0.97
## Renter Occupied 0.99
## Total_people 0.99
## Total With Disabilities 0.99
## Hearing 0.98
## Vision difficulty 0.98
## cognative 0.99
## ambulatory difficulty 0.99
## Self-care difficulty 1.00
## Independent living difficulty 1.00
## No Disability 0.99
## DisabilityRate -0.16
## Independent living difficulty
## In labor force: 0.99
## Civilian labor force: 0.99
## Employed 0.99
## Unemployed 0.97
## In Armed Forces 0.70
## Not in labor force 1.00
## EmploymentRate -0.15
## UnemploymentRate 0.34
## NotInLaborForceRate 0.11
## Education_Total_students 0.99
## Education_Below_9th grade 0.93
## Education_9th to 12th grade_no diploma 0.99
## Education_High_school_graduate 0.98
## Education_Some college_no degree 0.98
## Education_Associates_degree 0.99
## Education_Bachelors_degree 0.98
## Education_Graduate_professional degree 0.97
## U.S. citizen 0.99
## Not a U.S. citizen 0.93
## Total_age 0.99
## Age_under_18 0.98
## Age_18_to_24 0.98
## Age_25_to_34 0.98
## Age_35_to_44 0.98
## Age_45_to_54 0.99
## Age_55_to_64 0.99
## Age_over_64 0.99
## Total 0.99
## Owner Occupied 0.98
## Renter Occupied 0.98
## Total_people 0.99
## Total With Disabilities 0.99
## Hearing 0.98
## Vision difficulty 0.98
## cognative 0.99
## ambulatory difficulty 0.99
## Self-care difficulty 1.00
## Independent living difficulty 1.00
## No Disability 0.99
## DisabilityRate -0.16
## No Disability DisabilityRate
## In labor force: 1.00 -0.29
## Civilian labor force: 1.00 -0.29
## Employed 1.00 -0.29
## Unemployed 0.98 -0.26
## In Armed Forces 0.73 -0.24
## Not in labor force 0.99 -0.21
## EmploymentRate -0.04 -0.80
## UnemploymentRate 0.31 0.03
## NotInLaborForceRate 0.00 0.87
## Education_Total_students 1.00 -0.26
## Education_Below_9th grade 0.95 -0.20
## Education_9th to 12th grade_no diploma 0.99 -0.18
## Education_High_school_graduate 0.97 -0.20
## Education_Some college_no degree 0.99 -0.25
## Education_Associates_degree 0.98 -0.24
## Education_Bachelors_degree 1.00 -0.31
## Education_Graduate_professional degree 0.98 -0.34
## U.S. citizen 1.00 -0.24
## Not a U.S. citizen 0.95 -0.30
## Total_age 1.00 -0.26
## Age_under_18 1.00 -0.27
## Age_18_to_24 1.00 -0.26
## Age_25_to_34 1.00 -0.27
## Age_35_to_44 1.00 -0.27
## Age_45_to_54 1.00 -0.26
## Age_55_to_64 0.99 -0.26
## Age_over_64 0.98 -0.23
## Total 1.00 -0.26
## Owner Occupied 0.98 -0.25
## Renter Occupied 0.99 -0.27
## Total_people 1.00 -0.26
## Total With Disabilities 0.99 -0.17
## Hearing 0.98 -0.18
## Vision difficulty 0.98 -0.11
## cognative 0.99 -0.16
## ambulatory difficulty 0.98 -0.14
## Self-care difficulty 0.99 -0.16
## Independent living difficulty 0.99 -0.16
## No Disability 1.00 -0.27
## DisabilityRate -0.27 1.00
# Install the knitr package if not already installed
# install.packages("knitr")
# Load the knitr package
library(knitr)
# Print the rounded correlation matrix as a table
kable(rounded_correlation_matrix)
| In labor force: | Civilian labor force: | Employed | Unemployed | In Armed Forces | Not in labor force | EmploymentRate | UnemploymentRate | NotInLaborForceRate | Education_Total_students | Education_Below_9th grade | Education_9th to 12th grade_no diploma | Education_High_school_graduate | Education_Some college_no degree | Education_Associates_degree | Education_Bachelors_degree | Education_Graduate_professional degree | U.S. citizen | Not a U.S. citizen | Total_age | Age_under_18 | Age_18_to_24 | Age_25_to_34 | Age_35_to_44 | Age_45_to_54 | Age_55_to_64 | Age_over_64 | Total | Owner Occupied | Renter Occupied | Total_people | Total With Disabilities | Hearing | Vision difficulty | cognative | ambulatory difficulty | Self-care difficulty | Independent living difficulty | No Disability | DisabilityRate | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| In labor force: | 1.00 | 1.00 | 1.00 | 0.97 | 0.73 | 0.99 | -0.03 | 0.31 | -0.02 | 1.00 | 0.94 | 0.98 | 0.97 | 0.99 | 0.98 | 1.00 | 0.98 | 1.00 | 0.95 | 1.00 | 0.99 | 1.00 | 1.00 | 1.00 | 1.00 | 0.99 | 0.98 | 1.00 | 0.98 | 0.99 | 1.00 | 0.99 | 0.98 | 0.97 | 0.99 | 0.98 | 0.99 | 0.99 | 1.00 | -0.29 |
| Civilian labor force: | 1.00 | 1.00 | 1.00 | 0.98 | 0.72 | 0.99 | -0.03 | 0.31 | -0.02 | 1.00 | 0.94 | 0.98 | 0.97 | 0.99 | 0.98 | 1.00 | 0.98 | 1.00 | 0.95 | 1.00 | 0.99 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.98 | 1.00 | 0.98 | 0.99 | 1.00 | 0.99 | 0.98 | 0.97 | 0.99 | 0.98 | 0.99 | 0.99 | 1.00 | -0.29 |
| Employed | 1.00 | 1.00 | 1.00 | 0.97 | 0.73 | 0.99 | -0.02 | 0.30 | -0.02 | 1.00 | 0.94 | 0.98 | 0.98 | 0.99 | 0.98 | 1.00 | 0.98 | 1.00 | 0.95 | 1.00 | 0.99 | 1.00 | 1.00 | 1.00 | 1.00 | 0.99 | 0.98 | 1.00 | 0.98 | 0.99 | 1.00 | 0.99 | 0.98 | 0.97 | 0.99 | 0.98 | 0.99 | 0.99 | 1.00 | -0.29 |
| Unemployed | 0.97 | 0.98 | 0.97 | 1.00 | 0.68 | 0.97 | -0.09 | 0.42 | 0.02 | 0.97 | 0.97 | 0.97 | 0.93 | 0.96 | 0.95 | 0.98 | 0.98 | 0.97 | 0.97 | 0.97 | 0.96 | 0.97 | 0.98 | 0.97 | 0.98 | 0.97 | 0.95 | 0.96 | 0.93 | 0.99 | 0.97 | 0.95 | 0.93 | 0.94 | 0.95 | 0.95 | 0.98 | 0.97 | 0.98 | -0.26 |
| In Armed Forces | 0.73 | 0.72 | 0.73 | 0.68 | 1.00 | 0.72 | -0.05 | 0.17 | -0.04 | 0.72 | 0.71 | 0.74 | 0.66 | 0.75 | 0.70 | 0.73 | 0.71 | 0.72 | 0.72 | 0.73 | 0.74 | 0.74 | 0.74 | 0.74 | 0.73 | 0.70 | 0.68 | 0.71 | 0.70 | 0.72 | 0.73 | 0.71 | 0.72 | 0.73 | 0.71 | 0.71 | 0.71 | 0.70 | 0.73 | -0.24 |
| Not in labor force | 0.99 | 0.99 | 0.99 | 0.97 | 0.72 | 1.00 | -0.11 | 0.32 | 0.07 | 1.00 | 0.93 | 0.99 | 0.98 | 0.99 | 0.99 | 0.99 | 0.97 | 1.00 | 0.94 | 1.00 | 0.98 | 0.99 | 0.99 | 0.99 | 1.00 | 1.00 | 0.99 | 0.99 | 0.98 | 0.99 | 1.00 | 1.00 | 0.99 | 0.98 | 0.99 | 0.99 | 1.00 | 1.00 | 0.99 | -0.21 |
| EmploymentRate | -0.03 | -0.03 | -0.02 | -0.09 | -0.05 | -0.11 | 1.00 | -0.45 | -0.96 | -0.06 | -0.10 | -0.13 | -0.10 | -0.05 | -0.08 | -0.02 | -0.01 | -0.07 | -0.03 | -0.05 | -0.03 | -0.04 | -0.04 | -0.04 | -0.06 | -0.07 | -0.10 | -0.05 | -0.05 | -0.05 | -0.05 | -0.13 | -0.11 | -0.18 | -0.13 | -0.16 | -0.16 | -0.15 | -0.04 | -0.80 |
| UnemploymentRate | 0.31 | 0.31 | 0.30 | 0.42 | 0.17 | 0.32 | -0.45 | 1.00 | 0.22 | 0.32 | 0.35 | 0.32 | 0.29 | 0.28 | 0.29 | 0.33 | 0.37 | 0.31 | 0.34 | 0.31 | 0.29 | 0.30 | 0.32 | 0.31 | 0.32 | 0.32 | 0.31 | 0.31 | 0.28 | 0.34 | 0.31 | 0.31 | 0.27 | 0.32 | 0.31 | 0.32 | 0.35 | 0.34 | 0.31 | 0.03 |
| NotInLaborForceRate | -0.02 | -0.02 | -0.02 | 0.02 | -0.04 | 0.07 | -0.96 | 0.22 | 1.00 | 0.02 | 0.04 | 0.09 | 0.07 | 0.01 | 0.05 | -0.03 | -0.05 | 0.03 | -0.04 | 0.01 | -0.01 | 0.00 | -0.01 | -0.01 | 0.01 | 0.02 | 0.06 | 0.01 | 0.02 | -0.01 | 0.01 | 0.10 | 0.08 | 0.14 | 0.10 | 0.13 | 0.11 | 0.11 | 0.00 | 0.87 |
| Education_Total_students | 1.00 | 1.00 | 1.00 | 0.97 | 0.72 | 1.00 | -0.06 | 0.32 | 0.02 | 1.00 | 0.94 | 0.99 | 0.98 | 0.99 | 0.99 | 1.00 | 0.98 | 1.00 | 0.95 | 1.00 | 0.99 | 0.99 | 1.00 | 1.00 | 1.00 | 1.00 | 0.99 | 1.00 | 0.98 | 0.99 | 1.00 | 0.99 | 0.99 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 1.00 | -0.26 |
| Education_Below_9th grade | 0.94 | 0.94 | 0.94 | 0.97 | 0.71 | 0.93 | -0.10 | 0.35 | 0.04 | 0.94 | 1.00 | 0.96 | 0.87 | 0.94 | 0.90 | 0.94 | 0.92 | 0.93 | 0.99 | 0.94 | 0.95 | 0.95 | 0.96 | 0.96 | 0.95 | 0.92 | 0.90 | 0.92 | 0.88 | 0.96 | 0.94 | 0.91 | 0.91 | 0.93 | 0.92 | 0.91 | 0.95 | 0.93 | 0.95 | -0.20 |
| Education_9th to 12th grade_no diploma | 0.98 | 0.98 | 0.98 | 0.97 | 0.74 | 0.99 | -0.13 | 0.32 | 0.09 | 0.99 | 0.96 | 1.00 | 0.96 | 0.98 | 0.96 | 0.97 | 0.95 | 0.99 | 0.95 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.98 | 0.96 | 0.98 | 0.96 | 0.98 | 0.99 | 0.98 | 0.98 | 0.99 | 0.98 | 0.98 | 0.99 | 0.99 | 0.99 | -0.18 |
| Education_High_school_graduate | 0.97 | 0.97 | 0.98 | 0.93 | 0.66 | 0.98 | -0.10 | 0.29 | 0.07 | 0.98 | 0.87 | 0.96 | 1.00 | 0.96 | 0.98 | 0.96 | 0.94 | 0.98 | 0.87 | 0.98 | 0.97 | 0.97 | 0.96 | 0.97 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 0.96 | 0.98 | 0.99 | 0.99 | 0.97 | 0.99 | 0.99 | 0.97 | 0.98 | 0.97 | -0.20 |
| Education_Some college_no degree | 0.99 | 0.99 | 0.99 | 0.96 | 0.75 | 0.99 | -0.05 | 0.28 | 0.01 | 0.99 | 0.94 | 0.98 | 0.96 | 1.00 | 0.98 | 0.98 | 0.95 | 0.99 | 0.94 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.98 | 0.97 | 0.99 | 0.98 | 0.98 | 0.99 | 0.98 | 0.99 | 0.97 | 0.98 | 0.98 | 0.98 | 0.98 | 0.99 | -0.25 |
| Education_Associates_degree | 0.98 | 0.98 | 0.98 | 0.95 | 0.70 | 0.99 | -0.08 | 0.29 | 0.05 | 0.99 | 0.90 | 0.96 | 0.98 | 0.98 | 1.00 | 0.98 | 0.96 | 0.99 | 0.91 | 0.98 | 0.97 | 0.97 | 0.97 | 0.97 | 0.98 | 0.99 | 0.99 | 0.99 | 0.98 | 0.97 | 0.98 | 0.99 | 0.98 | 0.96 | 0.98 | 0.98 | 0.98 | 0.99 | 0.98 | -0.24 |
| Education_Bachelors_degree | 1.00 | 1.00 | 1.00 | 0.98 | 0.73 | 0.99 | -0.02 | 0.33 | -0.03 | 1.00 | 0.94 | 0.97 | 0.96 | 0.98 | 0.98 | 1.00 | 0.99 | 0.99 | 0.95 | 0.99 | 0.98 | 0.99 | 0.99 | 0.99 | 1.00 | 0.99 | 0.98 | 0.99 | 0.97 | 0.99 | 0.99 | 0.98 | 0.97 | 0.96 | 0.98 | 0.97 | 0.98 | 0.98 | 1.00 | -0.31 |
| Education_Graduate_professional degree | 0.98 | 0.98 | 0.98 | 0.98 | 0.71 | 0.97 | -0.01 | 0.37 | -0.05 | 0.98 | 0.92 | 0.95 | 0.94 | 0.95 | 0.96 | 0.99 | 1.00 | 0.97 | 0.93 | 0.98 | 0.96 | 0.97 | 0.97 | 0.97 | 0.98 | 0.98 | 0.97 | 0.97 | 0.95 | 0.98 | 0.98 | 0.95 | 0.94 | 0.93 | 0.95 | 0.95 | 0.97 | 0.97 | 0.98 | -0.34 |
| U.S. citizen | 1.00 | 1.00 | 1.00 | 0.97 | 0.72 | 1.00 | -0.07 | 0.31 | 0.03 | 1.00 | 0.93 | 0.99 | 0.98 | 0.99 | 0.99 | 0.99 | 0.97 | 1.00 | 0.94 | 1.00 | 0.99 | 1.00 | 0.99 | 1.00 | 1.00 | 1.00 | 0.98 | 1.00 | 0.99 | 0.99 | 1.00 | 0.99 | 0.99 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 1.00 | -0.24 |
| Not a U.S. citizen | 0.95 | 0.95 | 0.95 | 0.97 | 0.72 | 0.94 | -0.03 | 0.34 | -0.04 | 0.95 | 0.99 | 0.95 | 0.87 | 0.94 | 0.91 | 0.95 | 0.93 | 0.94 | 1.00 | 0.95 | 0.95 | 0.95 | 0.96 | 0.96 | 0.95 | 0.93 | 0.91 | 0.93 | 0.88 | 0.96 | 0.95 | 0.91 | 0.91 | 0.91 | 0.91 | 0.91 | 0.94 | 0.93 | 0.95 | -0.30 |
| Total_age | 1.00 | 1.00 | 1.00 | 0.97 | 0.73 | 1.00 | -0.05 | 0.31 | 0.01 | 1.00 | 0.94 | 0.99 | 0.98 | 0.99 | 0.98 | 0.99 | 0.98 | 1.00 | 0.95 | 1.00 | 0.99 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.98 | 1.00 | 0.98 | 0.99 | 1.00 | 0.99 | 0.99 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 1.00 | -0.26 |
| Age_under_18 | 0.99 | 0.99 | 0.99 | 0.96 | 0.74 | 0.98 | -0.03 | 0.29 | -0.01 | 0.99 | 0.95 | 0.99 | 0.97 | 0.99 | 0.97 | 0.98 | 0.96 | 0.99 | 0.95 | 0.99 | 1.00 | 1.00 | 1.00 | 1.00 | 0.99 | 0.98 | 0.96 | 0.99 | 0.98 | 0.99 | 0.99 | 0.98 | 0.98 | 0.98 | 0.98 | 0.98 | 0.98 | 0.98 | 1.00 | -0.27 |
| Age_18_to_24 | 1.00 | 1.00 | 1.00 | 0.97 | 0.74 | 0.99 | -0.04 | 0.30 | 0.00 | 0.99 | 0.95 | 0.99 | 0.97 | 0.99 | 0.97 | 0.99 | 0.97 | 1.00 | 0.95 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.99 | 0.97 | 0.99 | 0.98 | 0.99 | 1.00 | 0.99 | 0.98 | 0.98 | 0.99 | 0.98 | 0.98 | 0.98 | 1.00 | -0.26 |
| Age_25_to_34 | 1.00 | 1.00 | 1.00 | 0.98 | 0.74 | 0.99 | -0.04 | 0.32 | -0.01 | 1.00 | 0.96 | 0.99 | 0.96 | 0.99 | 0.97 | 0.99 | 0.97 | 0.99 | 0.96 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.99 | 0.97 | 0.99 | 0.97 | 0.99 | 1.00 | 0.98 | 0.98 | 0.97 | 0.98 | 0.98 | 0.99 | 0.98 | 1.00 | -0.27 |
| Age_35_to_44 | 1.00 | 1.00 | 1.00 | 0.97 | 0.74 | 0.99 | -0.04 | 0.31 | -0.01 | 1.00 | 0.96 | 0.99 | 0.97 | 0.99 | 0.97 | 0.99 | 0.97 | 1.00 | 0.96 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.99 | 0.97 | 0.99 | 0.98 | 0.99 | 1.00 | 0.98 | 0.98 | 0.98 | 0.98 | 0.98 | 0.99 | 0.98 | 1.00 | -0.27 |
| Age_45_to_54 | 1.00 | 1.00 | 1.00 | 0.98 | 0.73 | 1.00 | -0.06 | 0.32 | 0.01 | 1.00 | 0.95 | 0.99 | 0.98 | 0.99 | 0.98 | 1.00 | 0.98 | 1.00 | 0.95 | 1.00 | 0.99 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.98 | 1.00 | 0.98 | 0.99 | 1.00 | 0.99 | 0.98 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 1.00 | -0.26 |
| Age_55_to_64 | 0.99 | 1.00 | 0.99 | 0.97 | 0.70 | 1.00 | -0.07 | 0.32 | 0.02 | 1.00 | 0.92 | 0.98 | 0.99 | 0.98 | 0.99 | 0.99 | 0.98 | 1.00 | 0.93 | 1.00 | 0.98 | 0.99 | 0.99 | 0.99 | 1.00 | 1.00 | 0.99 | 1.00 | 0.99 | 0.99 | 1.00 | 0.99 | 0.98 | 0.97 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | -0.26 |
| Age_over_64 | 0.98 | 0.98 | 0.98 | 0.95 | 0.68 | 0.99 | -0.10 | 0.31 | 0.06 | 0.99 | 0.90 | 0.96 | 0.99 | 0.97 | 0.99 | 0.98 | 0.97 | 0.98 | 0.91 | 0.98 | 0.96 | 0.97 | 0.97 | 0.97 | 0.98 | 0.99 | 1.00 | 0.99 | 0.98 | 0.97 | 0.98 | 0.99 | 0.98 | 0.96 | 0.98 | 0.99 | 0.98 | 0.99 | 0.98 | -0.23 |
| Total | 1.00 | 1.00 | 1.00 | 0.96 | 0.71 | 0.99 | -0.05 | 0.31 | 0.01 | 1.00 | 0.92 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 0.97 | 1.00 | 0.93 | 1.00 | 0.99 | 0.99 | 0.99 | 0.99 | 1.00 | 1.00 | 0.99 | 1.00 | 0.99 | 0.99 | 1.00 | 0.99 | 0.99 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 1.00 | -0.26 |
| Owner Occupied | 0.98 | 0.98 | 0.98 | 0.93 | 0.70 | 0.98 | -0.05 | 0.28 | 0.02 | 0.98 | 0.88 | 0.96 | 0.99 | 0.98 | 0.98 | 0.97 | 0.95 | 0.99 | 0.88 | 0.98 | 0.98 | 0.98 | 0.97 | 0.98 | 0.98 | 0.99 | 0.98 | 0.99 | 1.00 | 0.96 | 0.98 | 0.99 | 0.99 | 0.97 | 0.99 | 0.99 | 0.97 | 0.98 | 0.98 | -0.25 |
| Renter Occupied | 0.99 | 0.99 | 0.99 | 0.99 | 0.72 | 0.99 | -0.05 | 0.34 | -0.01 | 0.99 | 0.96 | 0.98 | 0.96 | 0.98 | 0.97 | 0.99 | 0.98 | 0.99 | 0.96 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.97 | 0.99 | 0.96 | 1.00 | 0.99 | 0.98 | 0.97 | 0.96 | 0.98 | 0.97 | 0.99 | 0.98 | 0.99 | -0.27 |
| Total_people | 1.00 | 1.00 | 1.00 | 0.97 | 0.73 | 1.00 | -0.05 | 0.31 | 0.01 | 1.00 | 0.94 | 0.99 | 0.98 | 0.99 | 0.98 | 0.99 | 0.98 | 1.00 | 0.95 | 1.00 | 0.99 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.98 | 1.00 | 0.98 | 0.99 | 1.00 | 0.99 | 0.99 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 1.00 | -0.26 |
| Total With Disabilities | 0.99 | 0.99 | 0.99 | 0.95 | 0.71 | 1.00 | -0.13 | 0.31 | 0.10 | 0.99 | 0.91 | 0.98 | 0.99 | 0.98 | 0.99 | 0.98 | 0.95 | 0.99 | 0.91 | 0.99 | 0.98 | 0.99 | 0.98 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.98 | 0.99 | 1.00 | 1.00 | 0.99 | 1.00 | 1.00 | 0.99 | 0.99 | 0.99 | -0.17 |
| Hearing | 0.98 | 0.98 | 0.98 | 0.93 | 0.72 | 0.99 | -0.11 | 0.27 | 0.08 | 0.99 | 0.91 | 0.98 | 0.99 | 0.99 | 0.98 | 0.97 | 0.94 | 0.99 | 0.91 | 0.99 | 0.98 | 0.98 | 0.98 | 0.98 | 0.98 | 0.98 | 0.98 | 0.99 | 0.99 | 0.97 | 0.99 | 1.00 | 1.00 | 0.99 | 1.00 | 0.99 | 0.98 | 0.98 | 0.98 | -0.18 |
| Vision difficulty | 0.97 | 0.97 | 0.97 | 0.94 | 0.73 | 0.98 | -0.18 | 0.32 | 0.14 | 0.98 | 0.93 | 0.99 | 0.97 | 0.97 | 0.96 | 0.96 | 0.93 | 0.98 | 0.91 | 0.98 | 0.98 | 0.98 | 0.97 | 0.98 | 0.98 | 0.97 | 0.96 | 0.98 | 0.97 | 0.96 | 0.98 | 0.99 | 0.99 | 1.00 | 0.99 | 0.99 | 0.98 | 0.98 | 0.98 | -0.11 |
| cognative | 0.99 | 0.99 | 0.99 | 0.95 | 0.71 | 0.99 | -0.13 | 0.31 | 0.10 | 0.99 | 0.92 | 0.98 | 0.99 | 0.98 | 0.98 | 0.98 | 0.95 | 0.99 | 0.91 | 0.99 | 0.98 | 0.99 | 0.98 | 0.98 | 0.99 | 0.99 | 0.98 | 0.99 | 0.99 | 0.98 | 0.99 | 1.00 | 1.00 | 0.99 | 1.00 | 1.00 | 0.99 | 0.99 | 0.99 | -0.16 |
| ambulatory difficulty | 0.98 | 0.98 | 0.98 | 0.95 | 0.71 | 0.99 | -0.16 | 0.32 | 0.13 | 0.99 | 0.91 | 0.98 | 0.99 | 0.98 | 0.98 | 0.97 | 0.95 | 0.99 | 0.91 | 0.99 | 0.98 | 0.98 | 0.98 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 0.99 | 0.97 | 0.99 | 1.00 | 0.99 | 0.99 | 1.00 | 1.00 | 0.99 | 0.99 | 0.98 | -0.14 |
| Self-care difficulty | 0.99 | 0.99 | 0.99 | 0.98 | 0.71 | 1.00 | -0.16 | 0.35 | 0.11 | 0.99 | 0.95 | 0.99 | 0.97 | 0.98 | 0.98 | 0.98 | 0.97 | 0.99 | 0.94 | 0.99 | 0.98 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 0.98 | 0.99 | 0.97 | 0.99 | 0.99 | 0.99 | 0.98 | 0.98 | 0.99 | 0.99 | 1.00 | 1.00 | 0.99 | -0.16 |
| Independent living difficulty | 0.99 | 0.99 | 0.99 | 0.97 | 0.70 | 1.00 | -0.15 | 0.34 | 0.11 | 0.99 | 0.93 | 0.99 | 0.98 | 0.98 | 0.99 | 0.98 | 0.97 | 0.99 | 0.93 | 0.99 | 0.98 | 0.98 | 0.98 | 0.98 | 0.99 | 0.99 | 0.99 | 0.99 | 0.98 | 0.98 | 0.99 | 0.99 | 0.98 | 0.98 | 0.99 | 0.99 | 1.00 | 1.00 | 0.99 | -0.16 |
| No Disability | 1.00 | 1.00 | 1.00 | 0.98 | 0.73 | 0.99 | -0.04 | 0.31 | 0.00 | 1.00 | 0.95 | 0.99 | 0.97 | 0.99 | 0.98 | 1.00 | 0.98 | 1.00 | 0.95 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 0.99 | 0.98 | 1.00 | 0.98 | 0.99 | 1.00 | 0.99 | 0.98 | 0.98 | 0.99 | 0.98 | 0.99 | 0.99 | 1.00 | -0.27 |
| DisabilityRate | -0.29 | -0.29 | -0.29 | -0.26 | -0.24 | -0.21 | -0.80 | 0.03 | 0.87 | -0.26 | -0.20 | -0.18 | -0.20 | -0.25 | -0.24 | -0.31 | -0.34 | -0.24 | -0.30 | -0.26 | -0.27 | -0.26 | -0.27 | -0.27 | -0.26 | -0.26 | -0.23 | -0.26 | -0.25 | -0.27 | -0.26 | -0.17 | -0.18 | -0.11 | -0.16 | -0.14 | -0.16 | -0.16 | -0.27 | 1.00 |
# Assuming 'correlation_matrix' is your correlation matrix
employment_correlations <- correlation_matrix["EmploymentRate", ]
# Remove the correlation of EmploymentRate with itself
employment_correlations <- employment_correlations[employment_correlations != 1]
# Convert to data frame for plotting
correlation_df <- data.frame(
Variable = names(employment_correlations),
Correlation = employment_correlations
)
library(ggplot2)
# Plotting
ggplot(correlation_df, aes(x = reorder(Variable, Correlation), y = Correlation)) +
geom_bar(stat = "identity", fill = "steelblue") +
coord_flip() + # Flips the coordinates to make the plot horizontal
labs(title = "Correlation of Various Factors with Employment Rate",
x = "Variable",
y = "Correlation with Employment Rate") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
library(dplyr)
library(ggplot2)
library(corrplot)
# Calculating correlations
corr_matrix <- cor(rounded_correlation_matrix)
# Plotting the heatmap
corrplot(corr_matrix, method = "color")
# Load the plotly and dplyr libraries
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(dplyr)
X_variable <- "Unemployed"
Y_variables <- c("Education_Bachelors_degree", "Education_Graduate_professional degree", "Education_Below_9th grade", "Education_High_school_graduate")
# Convert data from wide to long format for easier plotting
long_data <- merged_data %>%
select(all_of(c(X_variable, Y_variables))) %>%
gather(key = "variable", value = "value", -all_of(X_variable))
# Create an interactive scatter plot
plotly_scatter <- long_data %>%
plot_ly(x = ~Unemployed, y = ~value, text = ~variable, mode = "markers", color = ~variable) %>%
add_markers(marker = list(size = 10)) %>%
layout(title = "Interactive Scatter Plot: Un-Employed vs. Education Levels",
xaxis = list(title = "Un-Employed"),
yaxis = list(title = "Value"),
hovermode = "closest")
# Show the interactive plot
plotly_scatter
# Assuming 'merged_data' is your merged dataset with employment and housing information
# Assuming 'ggplot2' is already loaded
# Create a scatter plot
ggplot(merged_data, aes(x = `Owner Occupied`, y = EmploymentRate)) +
geom_point() +
geom_smooth(method = "lm") +
labs(title = "Correlation between Owner-Occupied Housing and Employment Rate",
x = "Percentage of Owner-Occupied Housing",
y = "Employment Rate") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
library(ggplot2)
library(dplyr)
library(tidyr)
library(viridis)
## Loading required package: viridisLite
##
## Attaching package: 'viridis'
## The following object is masked from 'package:scales':
##
## viridis_pal
## The following object is masked from 'package:maps':
##
## unemp
X_variable <- "Unemployed"
Y_variables <- c("Age_18_to_24", "Age_25_to_34", "Age_45_to_54", "Age_55_to_64")
# Convert data from wide to long format for easier plotting
long_data <- merged_data %>%
select(all_of(c(X_variable, Y_variables))) %>%
gather(key = "variable", value = "value", -all_of(X_variable))
# Create the scatter plot
plot <- ggplot(long_data, aes_string(x = X_variable, y = "value", color = "variable")) +
geom_point() +
scale_color_viridis_d() + # Use a colorful scale
theme_minimal() + # Minimalist theme
labs(title = "Scatter Plots of Various Age vs Un-Employed Rate",
x = "Number of Unemployed",
y = "Value") +
scale_y_continuous(labels = scales::comma) +
scale_x_continuous(labels = scales::comma) +
theme(plot.title = element_text(hjust = 0.5), # Center the title
axis.text.x = element_text(angle = 45, hjust = 1)) # Slant x-axis labels
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
plotly_plot <- ggplotly(plot)
print(plotly_plot)
# Assuming 'merged_data' is your merged dataset with employment and housing information
# Assuming 'plotly' and 'dplyr' are already loaded
# Load the plotly library
library(plotly)
# Create an interactive scatter plot
plotly_scatter <- merged_data %>%
plot_ly(x = ~`Owner Occupied`, y = ~Unemployed, text = ~NAME, mode = "markers") %>%
add_markers(marker = list(color = "blue", size = 10)) %>%
layout(title = "Interactive Scatter Plot: Housing vs. Un-Employment",
xaxis = list(title = "Percentage of Owner-Occupied Housing"),
yaxis = list(title = "Un-Employment"),
hovermode = "closest")
# Show the interactive plot
plotly_scatter
library(plotly)
library(dplyr)
# Assuming 'merged_data' is your data frame and it contains columns
#"U.S. citizen", "Not a U.S. citizen"
# Create an interactive scatter plot
plotly_scatter <- merged_data %>%
plot_ly() %>%
add_trace(x = ~`U.S. citizen`, y = ~Unemployed, type = 'scatter', mode = 'markers',
marker = list(color = 'blue', size = 10), name = 'U.S. Citizen') %>%
add_trace(x = ~`Not a U.S. citizen`, y = ~Unemployed, type = 'scatter', mode = 'markers',
marker = list(color = 'red', size = 10), name = 'Not a U.S. Citizen') %>%
layout(title = 'Interactive Scatter Plot: Unemployment vs Citizenship Status',
xaxis = list(title = 'Citizenship Status'),
yaxis = list(title = 'Unemployment'),
hovermode = 'closest')
# Show the interactive plot
plotly_scatter